import { combineReducers } from 'redux';
import * as type from '../action/type';

const handleData = (state = {isFetching: true, data: {}}, action) => {
    switch (action.type) {
        case type.REQUEST_DATA:
            return {...state, isFetching: true};
        case type.RECEIVE_DATA:
            return {...state, isFetching: false, data: action.data};
        default:
            return {...state};
    }
};
const httpData = (state = {}, action) => {
    switch (action.type) {
        case type.RECEIVE_DATA:
        case type.REQUEST_DATA:
            return {
                ...state,
                [action.category]: handleData(state[action.category], action)
            };
        default:
            return {...state};
    }
};

const cardInfoInit = {
    brand_name: '品牌名称',
    title: '卡卷名',
    color: 'Color010',
    code_type: 'CODE_TYPE_QRCODE',
    member_supply: ['1']
}

const cardInfo = (state = cardInfoInit, action) => {
    switch(action.type){
        case 'CARDINFO':
        // console.log(action.payload)
            return {
                ...state,
                ...action.payload
            }
        default:
            return state
    }
}

export default combineReducers({
    httpData,
    cardInfo
});
